package com.famnote.getitbeauty;


import java.util.ArrayList;
import java.util.List;

import com.famnote.getitbeauty.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class DiscussArrayAdapter extends ArrayAdapter<OneComment> {

	private TextView nicknameView;
	private TextView commentView;
	private List<OneComment> comments = new ArrayList<OneComment>();
	private LinearLayout wrapper;

	@Override
	public void add(OneComment object) {
		comments.add(object);
		super.add(object);
	}

	
	public DiscussArrayAdapter(Context context, int textViewResourceId, ArrayList<OneComment> items) {
         super(context, textViewResourceId, items);
         comments = items;
	}
	 
	
	 
	public DiscussArrayAdapter(Context context, int textViewResourceId) {
		super(context, textViewResourceId);
	}

	public int getCount() {
		return this.comments.size();
	}

	public OneComment getItem(int index) {
		return this.comments.get(index);
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		if (row == null) {
			LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			row = inflater.inflate(R.layout.listitem_discuss, parent, false);
		}

		wrapper = (LinearLayout) row.findViewById(R.id.wrapper);

		////wrapper.setBackground(getResources().getColor(android.R.color.transparent));
		
		OneComment comment = getItem(position);

		nicknameView = (TextView) row.findViewById(R.id.nickname);
		commentView = (TextView) row.findViewById(R.id.comment);

		nicknameView.setText(comment.nickname);
		commentView.setText(Html.fromHtml(comment.comment));
		commentView.setMovementMethod(LinkMovementMethod.getInstance());
		
		///////countryName.setText(coment.comment);

		
		
		//countryName.setBackgroundResource(coment.left ? R.drawable.bubble_yellow : R.drawable.bubble_green);
		//wrapper.setGravity(comment.left ? Gravity.LEFT : Gravity.RIGHT);
		wrapper.setGravity(Gravity.LEFT);

		
		return row;
	}

	public Bitmap decodeToBitmap(byte[] decodedByte) {
		return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
	}

}

